import java.util.*;

class Solution {
    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
    public boolean isPalindrome(ListNode head) {
        List<Integer> vals = new ArrayList<>();
        while (head != null) {
            vals.add(head.val);
            head = head.next;
        }

        int start = 0;
        int end = vals.size() - 1;
        while (start < end) {
            if (!vals.get(start).equals(vals.get(end))) {
                return false;
            }
            start++;
            end--;
        }
        return true;
    }
}